<div class="site-dir"><?php
    echo $this->Html->link('Trang chủ', array('controller' => 'index', 'action' => 'index'));
    echo ' >> '.$this->Html->link('PTCS', array('controller' => 'subjects', 'action' => 'index'));
    echo ' >> '.$this->Html->link($test['Subject']['name'], array('controller' => 'subjects', 'action' => 'view', $test['Subject']['id']));
    echo ' >> '.$this->Html->link($test['Grade']['name'], array('controller' => 'subjects', 'action' => 'view', $test['Subject']['id'], $test['Grade']['id']));
    echo ' >> '.$test['Test']['name'];
?></div>
<div class="test-wraper"><!-- begin wraper -->
    <p><?php 
        echo '<span class="test-name">'.$test['Test']['name'].'</span>';
        echo $this->Html->image(grade_img($test['Subject']['id'], $test['Grade']['id']));
    ?>
        <span class="action-button"><?php echo $this->Html->link('Sửa', array('controller' => 'tests', 'action' => 'edithead', $test['Test']['id']));?></span>
        <span class="action-button"><?php echo $this->Html->link('Xóa', array('controller' => 'tests', 'action' => 'delete', $test['Test']['id']));?></span>
    </p>
    <div class="test-description">
        <?php if($test['User']['role'] == 'admin') {?>
        Của hệ thống
        <?php } else {?>
        Của <?php echo $this->Html->link($test['User']['username'], array('controller' => 'users', 'action' => 'view', $test['User']['id'])); }?>
        <br />
        Gửi lúc <b><?php echo $this->Time->format('G:i d/m/Y', $test['Test']['created']);?></b>
        <br />
        Số câu hỏi <b><?php echo $test['Test']['question_updated'];?> (<?php echo $test['Test']['normal_updated'];?> tự luận)</b>
    </div>
    <?php
        if($logged_in && (@$right_user || $this->Session->read('Chomo.Current.Role') == 'admin')) {
    ?>
    <table width="100%" border="0">
        <tr><td align="center" colspan="2"><?php echo $this->Session->flash();?></td></tr>
        <tr>
            <td align="left">
                <span class="view-mode">Đang ở chế độ chỉnh sửa</span> <span class="action-button"><?php echo $this->Html->link('Bình thường', array('controller' => 'tests', 'action' => 'view', $test['Test']['id']));?></span></i>
            </td>
            <td align="right">
                <span class="action-button right"><?php echo $this->Html->link('Thêm câu hỏi', array('controller' => 'questions', 'action' => 'add', $test['Test']['id'], 'choise'));?></span>
                <span class="action-button"><?php echo $this->Html->link('Các bộ đề cá nhân', array('controller' => 'tests', 'action' => 'viewall'));?></span>
            </td>
        </tr>
    </table>
    <?php }
    if($questionTestView && !$questionNormalView) {
?>
<div><!-- begin -->
    <div class="test-body-top"></div>
    <div class="test-body-center">
    <div class="test-body">
<?php
        $i = 1; 
        foreach($questionTestView as $question) {
            if($i != 1){echo '<br /><br />';}
            echo '<span><b>Câu ' . $i . ':</b> ';
            echo $question['Question']['content'] . '</span>';
            ?>
            <span class="action-button"><?php echo $this->Html->link('Sửa', array('controller' => 'questions', 'action' => 'edit', $test['Test']['id'], $question['Question']['id']));?></span>
            <span class="action-button"><?php echo $this->Html->link('Xóa', array('controller' => 'questions', 'action' => 'delete', $test['Test']['id'], $question['Question']['id']));?></span>
            <span class="action-button"><?php echo $this->Html->link('Reset', array('controller' => 'questions', 'action' => 'fmclear', $test['Test']['id'], $question['Question']['id']));?></span>
            <?php
            $i++;
            /** print answers **/
            foreach($question['Answer'] as $answer) {
                echo '<br /><span class=\'answer\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $answer['label'] . '. ' . $answer['content'] . '</span>';
            }
        }
?>
    </div>
    </div>
    <div class="test-body-bottom"></div>
</div><!-- end -->
<?php 
    } else if(!$questionTestView && $questionNormalView) {
?>
<div><!-- begin -->
    <div class="test-body-top"></div>
    <div class="test-body-center">
    <div class="test-body">
<?php
        $i = 1; 
        foreach($questionNormalView as $question) {
            if($i != 1){echo '<br /><br />';}
            echo '<span><b>Câu ' . $i . ':</b> ';
            echo $question['Question']['content'] . '</span>';
            ?>
            <span class="action-button"><?php echo $this->Html->link('Sửa', array('controller' => 'questions', 'action' => 'edit', $test['Test']['id'], $question['Question']['id']));?></span>
            <span class="action-button"><?php echo $this->Html->link('Xóa', array('controller' => 'questions', 'action' => 'delete', $test['Test']['id'], $question['Question']['id']));?></span>
            <span class="action-button"><?php echo $this->Html->link('Reset', array('controller' => 'questions', 'action' => 'fmclear', $test['Test']['id'], $question['Question']['id']));?></span>
            <?php
            $i++;
        }
?>
    </div>
    </div>
    <div class="test-body-bottom"></div>
</div><!-- end -->
<?php 
    } else if($questionTestView && $questionNormalView) {
?>
    <span class="common-title">PHẦN TRẮC NGHIỆM</span>
<div><!-- begin -->
    <div class="test-body-top"></div>
    <div class="test-body-center">
    <div class="test-body">
<?php
        $i = 1; 
        foreach($questionTestView as $question) {
            if($i != 1){echo '<br /><br />';}
            echo '<span><b>Câu ' . $i . ':</b> ';
            echo $question['Question']['content'] . '</span>';
            ?>
            <span class="action-button"><?php echo $this->Html->link('Sửa', array('controller' => 'questions', 'action' => 'edit', $test['Test']['id'], $question['Question']['id']));?></span>
            <span class="action-button"><?php echo $this->Html->link('Xóa', array('controller' => 'questions', 'action' => 'delete', $test['Test']['id'], $question['Question']['id']));?></span>
            <span class="action-button"><?php echo $this->Html->link('Reset', array('controller' => 'questions', 'action' => 'fmclear', $test['Test']['id'], $question['Question']['id']));?></span>
            <?php
            $i++;
            /** print answers **/
            foreach($question['Answer'] as $answer) {
                echo '<br /><span class=\'answer\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $answer['label'] . '. ' . $answer['content'] . '</span>';
            }
        }
?>
    </div>
    </div>
    <div class="test-body-bottom"></div>
</div><!-- end -->
    <br />
    <span class="common-title">PHẦN TỰ LUẬN</span>
<div><!-- begin -->
    <div class="test-body-top"></div>
    <div class="test-body-center">
    <div class="test-body">
<?php
        $i = 1; 
        foreach($questionNormalView as $question) {
            if($i != 1){echo '<br /><br />';}
            echo '<span><b>Câu ' . $i . ':</b> ';
            echo $question['Question']['content'] . '</span>';
            ?>
            <span class="action-button"><?php echo $this->Html->link('Sửa', array('controller' => 'questions', 'action' => 'edit', $test['Test']['id'], $question['Question']['id']));?></span>
            <span class="action-button"><?php echo $this->Html->link('Xóa', array('controller' => 'questions', 'action' => 'delete', $test['Test']['id'], $question['Question']['id']));?></span>
            <span class="action-button"><?php echo $this->Html->link('Reset', array('controller' => 'questions', 'action' => 'fmclear', $test['Test']['id'], $question['Question']['id']));?></span>
            <?php
            $i++;
        }
?>
    </div>
    </div>
    <div class="test-body-bottom"></div>
</div><!-- end -->
<?php        
    } else {
?>
<div><!-- begin -->
    <div class="test-body-top"></div>
    <div class="test-body-center">
    <div class="test-body">
<?php
        echo '<center>Đề này chưa có nội dung</center>';
?>
    </div>
    </div>
    <div class="test-body-bottom"></div>
</div><!-- end -->
<?php  }?>
    <br />
    <span class="common-title">Đáp án các câu trắc nghiệm </span><?php echo $this->Html->link('Hiện/Ẩn', '#', array('class' => 'show_hide'));?>
<div><!-- begin -->
    <div class="test-body-top"></div>
    <div class="test-body-center">
    <div class="test-body slidingDiv">
        <table width="100%" cellspacing="0" border="0">
<?php
            if($questionTestView) {
                $i = 1;
                foreach($questionTestView as $question) {
                    if($i%2 != 0) {
?>
                        <tr><td width="50%">
<?php
                            echo '<b>Câu '.$i.':</b>  ';
                            foreach($question['Answer'] as $answer) {
                                if($answer['right'] == 1) {
                                    echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>'.$answer['label'].'</b>: '.$answer['content'];
                                }
                            }
?>
                        </td>
<?php
                    } else {
?>
                        <td>
<?php
                            echo '<b>Câu '.$i.':</b>  ';
                            foreach($question['Answer'] as $answer) {
                                if($answer['right'] == 1) {
                                    echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>'.$answer['label'].'</b>: '.$answer['content'];
                                }
                            }
?>
                        </td></tr>
<?php
                    }
                    $i++;
                }
                if($i%2 == 0) {
?>
                        <td></td></tr>
<?php
                }
            } else {
                echo '<tr><td><center>------</center></td></tr>';
            }
?>
        </table>
    </div>
    </div>
    <div class="test-body-bottom"></div>
</div><!-- end -->
</div><!-- end wraper -->
<?php
function grade_img($subjectId, $gradeId) {
    if($subjectId == 1) {
        return 'subjects/ToanHoc/'.$gradeId.'.gif';
    }
    if($subjectId == 2) {
        return 'subjects/VatLy/'.$gradeId.'.gif';
    }
    if($subjectId == 3) {
        return 'subjects/HoaHoc/'.$gradeId.'.gif';
    }
    if($subjectId == 4) {
        return 'subjects/SinhHoc/'.$gradeId.'.gif';
    }
    if($subjectId == 5) {
        return 'subjects/NguVan/'.$gradeId.'.gif';
    }
    if($subjectId == 6) {
        return 'subjects/LichSu/'.$gradeId.'.gif';
    }
    if($subjectId == 7) {
        return 'subjects/DiaLy/'.$gradeId.'.gif';
    }
    if($subjectId == 8) {
        return 'subjects/TiengAnh/'.$gradeId.'.gif';
    }
    if($subjectId == 9) {
        return 'subjects/TinHoc/'.$gradeId.'.gif';
    }
    if($subjectId == 10) {
        return 'subjects/CongNghe/'.$gradeId.'.gif';
    }
    if($subjectId == 11) {
        return 'subjects/Khac/'.$gradeId.'.gif';
    }
}
?>